/*
moxl - Modular XML Library
Copyright (c) 2007, Malcolm Sparks

This program is free software; you can redistribute it and/or
modify it under the terms of the GNU General Public License
as published by the Free Software Foundation; either version 2
of the License, or (at your option) any later version.

This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
GNU General Public License for more details.

You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
*/
package moxl.raw.stubs;

import java.util.Collection;
import java.util.HashMap;
import java.util.LinkedList;
import java.util.List;
import java.util.Map;

import moxl.raw.ElementLocation;
import moxl.raw.RawAttribute;
import moxl.raw.RawCharacterData;
import moxl.raw.RawDocument;
import moxl.raw.RawElement;
import moxl.raw.RawNode;

public class RawElementImplementation implements RawElement
{
	private final String localName;
	private final List<RawNode> childNodes = new LinkedList<RawNode>();
	private final Map<String, RawAttributeImplementation> attributes = new HashMap<String, RawAttributeImplementation>();

	public RawElementImplementation(String localName)
	{
		this.localName = localName;
	}

	public Collection<RawNode> getChildNodes()
	{
		return childNodes;
	}

	public String getTag()
	{
		return localName;
	}

	public Collection<? extends RawAttribute> getAttributes()
	{
		return attributes.values();
	}

	public ElementLocation getLocation()
	{
		throw new UnsupportedOperationException(
		        "TODO: Suppose this should return null, but null in this context is dangerous- perhaps have a hasLocation method");
	}

	public boolean hasLocation()
	{
		return false;
	}

	public void setAttribute(String name, String value)
	{
		attributes.put(name, new RawAttributeImplementation(name, value));
	}

	public boolean containsCharacterData()
	{
		for (RawNode node : childNodes)
		{
			if (node instanceof RawCharacterData)
			{
				return true;
			}
		}
		return false;
	}

	public int countNodes()
	{
		return childNodes.size();
	}

	public int countElements()
    {
	    throw new UnsupportedOperationException("TODO");
    }

	public RawDocument getOwningDocument()
    {
	    throw new UnsupportedOperationException();
    }

	public RawNode getChildNode(int index)
    {
	    throw new UnsupportedOperationException("TODO");
    }

	public boolean containsCharacterDataExcludingWhitespace()
    {
	    throw new UnsupportedOperationException("TODO");
    }

}
